pub enum Sex {
    Unknown,
    Male,
    Female,
}

impl From<Sex> for &str {
    fn from(val: Sex) -> Self {
        match val {
            Sex::Male => "male",
            Sex::Female => "female",
            Sex::Unknown => "unknown",
        }
    }
}


#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Role {
    Manager,
    Headmaster,
    Teacher,
    Student,
    Guest,
}

impl Role{
    // 给每个角色一个编号，通过数字大小来决定是否有该权限
    pub fn order(self) -> usize {
        let roles = vec![Role::Guest, Role::Student, Role::Teacher, Role::Headmaster, Role::Manager];
        for i in 0..roles.len() {
            if self == roles[i] {
                return i;
            }
        }
        0
    }
}


// impl From<Roles> for &str {
//     fn from(r: Roles) -> Self {
//         match r {
//             Roles::Manager => { "manager" }
//             Roles::Headmaster => { "headmaster" }
//             Roles::Teacher => { "teacher" }
//             Roles::Student => { "student" }
//             Roles::Guest => { "guest" }
//         }
//     }
// }

// manager, headmaster, teacher, student, guest
impl Into<String> for Role {
    fn into(self) -> String {
        let ret = match self {
            Role::Manager => { "manager" }
            Role::Headmaster => { "headmaster" }
            Role::Teacher => { "teacher" }
            Role::Student => { "student" }
            Role::Guest => { "guest" }
        };
        ret.to_string()
    }
}

impl From<String> for Role {
    fn from(v: String) -> Self {
        if v.eq("manager") {
            return Role::Manager;
        } else if v.eq("headmaster") {
            return Role::Headmaster;
        } else if v.eq("teacher") {
            return Role::Teacher;
        } else if v.eq("student") {
            return Role::Student;
        }
        return Role::Guest;
    }
}

